<?php
	/**
	 * Récupère la liste des contacts associé à l'user(format array js)
	 * Necessite session OK
	 */
	function getContactsListDest()
	{
		include_once 'Util/includeAll.php';
		
		$u=getUser();
		
		if (isset($u))
		{
			$str='';
			$theOne = true;
			
			foreach ($u->contacts as $c)
			{
				if($theOne)
				{
					$str = "\"$c->name <$c->phoneNumber>\"";
					$theOne = false;
				}
				else
					$str = "$str,\"$c->name <$c->phoneNumber>\"";		
			}
			return $str;
		}
		else
			return '';
	}
	
	function getContactsListItems($selectedID = null){
		
		
		$u=getUser();
		
		if (isset($u))
		{
			$str='';
			
			foreach ($u->contacts as $c)
			{
				$nbMess = count($c->messages);
				$isSelectedClass = '';
				
				if ($selectedID)
				{
					if ($selectedID == $c->id)
					{
						$isSelectedClass = ' contactListItemSelected';
					}
				}

				$str.= '<div class="contactListItem blocBlanc '.$isSelectedClass.'" id="ContactItem'.$c->id.'" onclick="ShowConversation('.$c->id.');">';
				$str.= '<img class="profilImg contactImg" src="./img/droidProfilImg.png"/>';
				$str.= '<table style="display:inline; width:136px;">';
				$str.= '<tr>';
				$str.= '<td><b class="contactName">'.$c->name.'</b></td>';
				$str.= '<td align="right"><img class="ContactListImg" src="img/SMS_vert.png"/>'.$nbMess."</td>";
				$str.= '</tr>';
				$str.= '<tr>';
				$str.= '<td colspan="2"><span class="contactPhoneNumber">'.$c->phoneNumber.'</span></td>';
				$str.= '</tr>';
				$str.= '</table>';
				$str.= '</div>';
			}
			
			if ($str == '')
			{
				$str = "Aucun contact";
			}
			return $str;
		}
			else
				return '';
			
			

	}


?>